package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.system;

import org.springframework.data.domain.Page;
import com.glsc.ngateway.common.base.domain.mysql.gateway.system.SystemVendorLogInfo;
import com.glsc.ngateway.common.api.platform.dto.system.ParamSystemVendorLogInfoDto;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface SystemVendorLogInfoRepository extends JpaRepository<SystemVendorLogInfo, Integer>, JpaSpecificationExecutor<SystemVendorLogInfo> {

    @Query(value = "select m from SystemVendorLogInfo m where 1=1 " +
            "and (:#{#paramSearchDto.id} is null OR m.id = :#{#paramSearchDto.id})  " +
            "and (:#{#paramSearchDto.vendorId} is null OR m.vendorId = :#{#paramSearchDto.vendorId})  " +
            "and (:#{#paramSearchDto.vendorCode} is null OR m.vendorCode = :#{#paramSearchDto.vendorCode})  " +
            "and (:#{#paramSearchDto.vendorName} is null OR m.vendorName LIKE CONCAT('%',:#{#paramSearchDto.vendorName},'%') )  " +
//            "and (:#{#paramSearchDto.processDefineKey} is null OR m.processDefineKey = :#{#paramSearchDto.processDefineKey} )  " +
//            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode = :#{#paramSearchDto.systemCode} )  " +
//            "and (:#{#paramSearchDto.beginDateLocalDate} is null OR m.processCreateTime >= :#{#paramSearchDto.beginDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.endDateLocalDate} is null OR m.processCreateTime <= :#{#paramSearchDto.endDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.hasProcessEnd} is null OR m.isClose = :#{#paramSearchDto.hasProcessEnd} )  " +
//            "and (coalesce(:#{#paramSearchDto.adminList}, null) is null or m.systemAdminAccount in (:#{#paramSearchDto.adminList})) " +
            "and (:#{#paramSearchDto.deleted} is null OR m.deleted = :#{#paramSearchDto.deleted} )  " +
            "order by m.insertTime desc")
    Page<SystemVendorLogInfo> searchByParam(Pageable pageable, ParamSystemVendorLogInfoDto paramSearchDto);
}